package com.cherish.pattern.proxy.dynamicproxy.cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Classname CgLibMeiPo
 * @Date 2019/4/7 17:32
 * @Author admin
 * @Description TODO
 */
public class CgLibMeiPo implements MethodInterceptor {

    private Object tatget;

    public Object getInstants(Class clasz){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(clasz);
        enhancer.setCallback(this);
        return enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        before();
        return methodProxy.invokeSuper(o,objects);
    }

    private void before(){
        System.out.println("cglib before");
    }

}
